<template>
    <el-menu
        default-active="2"
        class="el-menu-vertical-demo"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b"
        :router="true"
    >
        <el-submenu
            index="1"
            :disabled="!(this.userType == '出租方' && adminDataSataus == 0)"
        >
            <template slot="title">
                <i class="el-icon-user-solid"></i>
                <span>出租方功能</span>
            </template>
            <el-menu-item-group>
                <el-menu-item index="/System/ParkingList"
                    >车位列表</el-menu-item
                >
                <el-menu-item index="/System/addparking">新增车位</el-menu-item>
                <el-menu-item index="/System/myorders">我的订单</el-menu-item>
                <el-menu-item index="/System/HistoryOrders"
                    >历史订单</el-menu-item
                >
            </el-menu-item-group>
        </el-submenu>
        <el-submenu index="2" :disabled="!(this.userType == '管理员')">
            <template slot="title">
                <i class="el-icon-s-custom"></i>
                <span>普通管理员</span>
            </template>
            <el-menu-item-group>
                <el-menu-item index="/system/makelessors"
                    >管理出租信息</el-menu-item
                >
                <el-menu-item index="/System/maketenants"
                    >管理租客信息</el-menu-item
                >
                <el-menu-item index="/System/makeorders"
                    >管理订单信息</el-menu-item
                >
                <el-menu-item index="/System/makeparkings"
                    >管理车位信息</el-menu-item
                >
            </el-menu-item-group>
        </el-submenu>
        <el-submenu
            index="3"
            :disabled="
                (this.userType == '出租方' && adminDataSataus == 0) ||
                adminDataSataus == 2
            "
        >
            <template slot="title">
                <i class="el-icon-location"></i>
                <span>超级管理员</span>
            </template>
            <el-menu-item-group>
                <el-menu-item index="/System/adminsSystem"
                    >管理员列表</el-menu-item
                >
                <el-menu-item index="/System/addAdmins"
                    >管理员新增</el-menu-item
                >
                <el-menu-item index="/System/seekAdmins"
                    >管理员搜索</el-menu-item
                >
                <el-menu-item index="/System/logslist">
                    日志管理（登录日志）</el-menu-item
                >
            </el-menu-item-group>
        </el-submenu>
    </el-menu>
</template>

<script>
//引入管理员仓库
import { createNamespacedHelpers } from "vuex";

const {
    mapState: adminsMapState,
    mapMutations: adminsMapMutations,
    mapActions: adminsMapActions,
} = createNamespacedHelpers("admins");

export default {
    data() {
        return {
            userType: "",
            adminsId: "",
        };
    },
    mounted() {
        let userTypeLc = localStorage.getItem("userType"); //获取登录的类型
        this.userType = userTypeLc;
        //如果登录的是管理员，获取管理员身份
        if (userTypeLc == "管理员") {
            this.adminsId = localStorage.getItem("_id"); //获取登录管理员的id值
            this.getAdmins({ _id: this.adminsId });
        } else {
            this.changeAdminDataSataus(0);
            console.log(
                this.adminDataSataus,
                "判断当前登录人员，0出租方，1超管，2普管"
            );
        }
    },
    computed: {
        ...adminsMapState(["adminDataSataus"]),
    },
    watch: {
        adminDataSataus() {
            console.log(
                this.adminDataSataus,
                "判断当前登录人员，0出租方，1超管，2普管"
            );
        },
    },
    methods: {
        ...adminsMapMutations(["changeAdminDataSataus"]),
        ...adminsMapActions(["getAdmins"]),
    },
};
</script>

<style>
</style>